Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rnfFoldableLTR and rnfFoldableRTL #18

Closed
wants to merge 1 commit into from

Conversation

treeowl
Copy link
Contributor

@treeowl treeowl commented Jul 17, 2016

If a type has a Foldable instance, then we can force it from
left to right or from right to left.

Fixes #17

If a type has a `Foldable` instance, then we can force it from
left to right or from right to left.

Fixes haskell#17
@RyanGlScott
Copy link
Member

For context: Haskell libraries mailing list discussion: https://mail.haskell.org/pipermail/libraries/2016-July/027164.html

@rwbarton
Copy link

This should carry a huge warning that it is normally not a sensible definition for Foldable instances where f a contains fields of types other than a, such as a pair.

@treeowl
Copy link
Contributor Author

treeowl commented Jul 27, 2016

It has such a warning, specifically mentioning Either a and (,) a. Is
the warning insufficient?

On Jul 27, 2016 5:03 PM, "Reid Barton" [email protected] wrote:

This should carry a huge warning that it is normally not a sensible
definition for Foldable instances where f a contains fields of types
other than a, such as a pair.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#18 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABzi_djQZ4CsXZJuz8q7fJP_0C8XJgpyks5qZ8esgaJpZM4JOIet
.

@rwbarton
Copy link

Oh, so it does. There is such a lot of noise in the diff that I missed it.


instance Monoid UnitLTR where
mempty = UnitLTR ()
UnitLTR () `mappend` y = y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid invoking the wrath of -Wnoncanonical-monoid-instances in later GHCs, it'd be prudent to define mappend like this:

instance Monoid UnitLTR where
  mempty = UnitLTR ()
#if MIN_VERSION_base(4,9,0)
  mappend = (<>)
#else
  UnitLTR () `mappend` y = y
#endif

And similarly for UnitRTL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@chessai
Copy link
Member

chessai commented May 3, 2019

This seems useful, can this be worked in to the modern deepseq?

@cartazio
Copy link

cartazio commented May 4, 2019 via email

@chessai
Copy link
Member

chessai commented Dec 29, 2019

Are we worried at all about the loss of Safe?

@mixphix
Copy link
Collaborator

mixphix commented Aug 25, 2024

foldMap can be more efficient than either foldl or foldr, so Unit was added by #106 (same as UnitLTR).

@mixphix mixphix closed this Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Offer Foldable helper
7 participants